#ifndef NP_SQLDEF_H
#define NP_SQLDEF_H

#define SQL_LENGTH 1024 * 2

#define SQL_BATCH_LENGTH 1024 * 1024

#define SQL_ARTICLE_SELECT_BYNAME "select * from jieqi_article_article where articlename = '%s';"

//#define SQL_ARTICLE_SELECT_BYNAME "select * from jieqi_article_article where locate(articlename, '%s')>0 COLLATE gbk_bin;"

#define SQL_ARTICLE_SELECT_LIST "select * from jieqi_article_article where lastupdate > %s order by lastupdate"

#define SQL_ATTACH_SELECT_LIST "select * from jieqi_article_attach where articleid = '%s' and chapterid='%s' order by attachid"

#define SQL_ARTICLE_SELECT_LIST_COUNT "select count(articleid) from jieqi_article_article "

#define SQL_ARTICLE_INSERT " insert into `jieqi_article_article` (\
`articleid`, `siteid`, `postdate`, `lastupdate`, `articlename`,`keywords`,\
`initial`, `authorid`, `author`, `posterid`,`poster`, `agentid`, \
`agent`, `sortid`, `typeid`, `intro`, `notice`, `setting`, \
`lastvolumeid`, `lastvolume`, `lastchapterid`, `lastchapter`,`chapters`, `size`,\
`lastvisit`, `dayvisit`, `weekvisit`, `monthvisit`,`allvisit`, `lastvote`,\
`dayvote`, `weekvote`, `monthvote`, `allvote`, `vipvotetime`, `vipvotenow`, \
`vipvotepreview`, `goodnum`, `badnum`, `toptime`, `saleprice`, `salenum`, \
`totalcost`, `articletype`, `permission`, `firstflag`, `fullflag`, `imgflag`,\
`power`, `display`,`downloadlink`)\
values ( \
    '%s','%s','%s','%s','%s','%s',\
    '%c','%s','%s','%s','%s','%s', \
    '%s','%s','%s','%s','%s','%s',\
    '%s','%s','%s','%s','%s','%s',\
    '%s','%s','%s','%s','%s','%s',\
    '%s','%s','%s','%s','%s','%s',\
    '%s','%s','%s','%s','%s','%s',\
    '%s','%c','%c','%c','%c','%c',\
    '%c','%c','%s');"
/*values ( \
    %s,%s,%s,%s,'%s','%s',\
    '%c',%s,'%s',%s,'%s',%s, \
    '%s',%s,%s,'%s','%s','%s',\
    %s,'%s',%s,'%s',%s,%s,\
    %s,%s,%s,%s,%s,%s,\
    %s,%s,%s,%s,%s,%s,\
    %s,%s,%s,%s,%s,%s,\
    %s,'%c','%c','%c','%c','%c',\
    '%c','%c','%s');"
*/
#define SQL_ARTICLE_UPDATE "update jieqi_article_article \
set `lastvolumeid`=%s, `lastvolume`='%s',`lastchapterid`='%s',`lastchapter`='%s', \
`chapters`='%s',`size`='%s' , `lastupdate`='%s'\
    where articleid='%s';"

#define SQL_ARTICLE_MAXID "select max(articleid) as  articleid from jieqi_article_article; "

#define SQL_ATTACH_MAXID "select max(attachid) as  articleid from jieqi_article_attach; "

#define SQL_CHAPTER_INSERT "INSERT INTO `jieqi_article_chapter`\
(`chapterid`,`siteid`,`articleid`,`articlename`,`volumeid`,\
`posterid`,`poster`,`postdate`,`lastupdate`,`chaptername`,\
`chapterorder`,`size`,`saleprice`,`salenum`,`totalcost`,\
`attachment`,`isvip`,`chaptertype`,`power`,`display`,`txtlink`)\
VALUES (\
    '%s','%s','%s','%s','%s',\
    '%s','%s','%s','%s','%s',\
    '%s','%s','%s','%s','%s',\
    '%s','%c','%c','%c','%c','%s');"

#define SQL_CHAPTER_UPDATE_TYPE "update jieqi_article_chapter set `ctype`='%s' where `chapterid`='%s'"

#define SQL_CHAPTER_SELECT "select * from jieqi_article_chapter where articleid=%s order by chapterorder;"

#define SQL_CHAPTER_SELECT_TIME "select * from jieqi_article_chapter where lastupdate >%s order by lastupdate limit %d;"

#define SQL_CHAPTER_MAXID "select max(chapterid) as chapterid from jieqi_article_chapter; "

#define SQL_ATTACH_INSERT "insert jieqi_article_attachs \
  (`attachid`,`articleid`,`chapterid`,\
`name`,`class`,`postfix`,\
`size`,`hits`,`needexp`,\
`uptime`,`isactive`)\
  values(\
  '%s','%s','%s',\
    '%s','%s','%s',\
    '%s','%s','%s',\
    '%s','%s');"

#define SQL_ATTACH_UPDATE_INVALID "update jieqi_article_attachs  set isactive ='0' where articleid=%s ;"

#endif // NP_SQLDEF_H
